package com.itheima03.day16test;

import java.io.*;
import java.net.Socket;

/**
 * @author 刘全
 * @date 2021/8/10
 */
public class ClientTest6 {
    public static void main(String[] args) throws IOException {
        /**
         * 6. 使用TCP完成文件上传。
         */
        Socket s = new Socket("127.0.0.1", 10086);

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\lq\\Desktop\\搞笑\\mbg.gif"));

        OutputStream os = s.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);

        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
        bos.flush();
        s.shutdownOutput();


        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        bis.close();
        s.close();
    }
}
